﻿using Microsoft.Office.Interop.Excel;
using PanhuaWin.系统管理;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DataTable = System.Data.DataTable;

namespace PanhuaWin.通用
{
    public partial class Form已轧硬未完工 : UIForm
    {
        public string 工厂编号;
        public Bus_PicklingOutput 卷信息 = new Bus_PicklingOutput();
        public Form已轧硬未完工()
        {
            InitializeComponent();
        }

        private void uiButton查询_Click(object sender, EventArgs e)
        {
            ListData();
        }

        private void ListData()
        {
            string sql;
            sql = @"SELECT row_number() over(order by  时间,卷号 ) 序号,   工厂编号, 时间, 卷号, 规格型号, 材质, 重量, 米数, 质量等级, 质量信息  FROM      View_已酸洗轧硬未镀锌  where 1=1  ";
            sql += " and 工厂编号='" + 工厂编号 + "' and 时间>='" + this.uiDatePicker开始日期.Value.ToString("yyyy-MM-dd") + "' ";
            sql += " and 时间<'" + this.uiDatePicker结束日期.Value.AddDays(1).ToString("yyyy-MM-dd") + "'";
            if (this.uiComboBox材质.SelectedText != "全部")
            {
                sql += " and 材质 ='" + this.uiComboBox材质.SelectedText + "'";
            }
            if (this.uiTextBox规格型号.Text.Trim() != "")
            {
                sql += " and 规格型号 ='" + this.uiTextBox规格型号.Text.Trim().Replace("--", "") + "'";
            }
           
            if (this.uiTextBox卷号.Text.Trim() != "")
            {
                sql += " and 卷号 like '%" + this.uiTextBox卷号.Text.Trim().Replace("--", "") + "%'";
            }
            
            


            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {

                this.uiDataGridView已发未结束.AutoGenerateColumns = false;
                this.uiDataGridView已发未结束.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                this.uiDataGridView已发未结束.DataSource = tb;
                this.uiDataGridView已发未结束.Refresh();
            }
            else
            {
                this.uiDataGridView已发未结束.DataSource = null;
                this.uiDataGridView已发未结束.Refresh();
                MessageBox.Show("没有已轧硬未镀锌的卷可以选择", "提示", MessageBoxButtons.OK);
                return;

            }


        }

        private void Form已发未完工卷_Load(object sender, EventArgs e)
        {
            this.uiDatePicker开始日期.Value = DateTime.Today.AddMonths(-1);
            this.uiDatePicker结束日期.Value = DateTime.Today;
            pub.ListSteelAll(this.uiComboBox材质);


            //pub.ListNextWorkTypeBytWorkTypeAll(工厂编号, "轧硬", this.uiComboBox去向);

        }

        private void uiDataGridView已发未结束_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (this.uiDataGridView已发未结束.Columns[e.ColumnIndex].Name == "C选择")
                {
                    //出库卷信息.guid = Guid.Parse(this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["Cguid"].Value.ToString());
                    卷信息.OutputVolumeNew = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C卷号"].Value.ToString();
                    卷信息.OutputSize = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C规格型号"].Value.ToString();
                    //string[] s = 卷信息.OutputSize.Split('*');
                    //卷信息.OutputThick = pub.Todecimal( s[0]); 
                    //卷信息.OutputWidth = pub.Todecimal (s[1] );
                    卷信息.OutputMeter = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C米数"].Value.ToString();
                    卷信息.OutputMaterial = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C材质"].Value.ToString();
                    //卷信息.OutputNext = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C去向"].Value.ToString();
                    卷信息.OutputWeight = pub.Todecimal(this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C重量"].Value.ToString());
                    //出库卷信息.InventoryName = this.uiDataGridView已发未结束.Rows[e.RowIndex].Cells["C存货名称"].Value.ToString();
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
        }
    }
}
